package com.ying.user.controller;

import com.ying.common.entity.Response;
import com.ying.user.entity.dto.*;
import com.ying.user.service.MmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.function.Function;

@RestController
@RequestMapping(value = "/mmUser")
public class MmUserController {

    @Autowired
    private MmUserService mmuserService;

    @PostMapping(value = "/register")
    public Response register(@RequestBody MmUserRegister mmUserRegister) {
        Function<MmUserRegister, Response> register = mmuserService.register();
        return register.apply(mmUserRegister);
    }

    @PostMapping(value = "/login")
    public Response login(@RequestBody MmUserLogin mmUserLogin) {
        Function<MmUserLogin, Response> login = mmuserService.login();
        return login.apply(mmUserLogin);
    }

    @GetMapping("/logout")
    public Response logout(HttpServletRequest request) {
        Function<HttpServletRequest, Response> logout = mmuserService.logout();
        return logout.apply(request);
    }

    @GetMapping(value = "/sendSms")
    public Response sendSms(@RequestParam String telephone) {
        Function<String, Response> sendSms = mmuserService.sendSms();
        return sendSms.apply(telephone);
    }

    @PostMapping(value = "/forget")
    public Response forget(@RequestBody MmUserForget mmUserForget) {
        Function<MmUserForget, Response> forget = mmuserService.forget();
        return forget.apply(mmUserForget);
    }

    @PostMapping(value = "/reset")
    public Response reset(@RequestBody MmUserReset mmUserReset) {
        Function<MmUserReset, Response> reset = mmuserService.reset();
        return reset.apply(mmUserReset);
    }

    //-----------------------------MmUser 操作-----------------------------------------

    @PostMapping(value = "/add")
    public Response add(@RequestBody MmUserAdd mmUserAdd) {
        Function<MmUserAdd, Response> add = mmuserService.add();
        return add.apply(mmUserAdd);
    }
}
